package cn.itsource.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String  SPRINGBOOT_EXCHANGE="springboot_exchange";
    public  static  final String SPRINGBOOT_QUEUE1="springboot_queue1";
    public  static  final String SPRINGBOOT_QUEUE2="springboot_queue2";

/*
*1.创建一个交换机
* 2.创建两个队列
* 3.把交换机和队列绑定到一起，交给spring管理
* */
           @Bean
        public Exchange createExchange(){

               //创建一个交换机对象
           return (Exchange) ExchangeBuilder.topicExchange(SPRINGBOOT_EXCHANGE).durable(true).build();

        }

           @Bean
        public Queue userQueue(){

            Queue queue = new Queue(SPRINGBOOT_QUEUE1);
            return queue;

        }
           @Bean
        public Queue productQueue(){

            Queue queue = new Queue(SPRINGBOOT_QUEUE2);
            return queue;

        }

        @Bean
    public Binding bind1(){

     return BindingBuilder.bind(userQueue()).
     to(createExchange()).with("user.*").noargs();

        }
        @Bean
    public Binding bind2(){

     return BindingBuilder.bind(productQueue()).
     to(createExchange()).with("product.*").noargs();

        }








}
